package com.manxi.controller.admin;


import com.manxi.dto.TrendsDTO;
import com.manxi.dto.TrendsPageQueryDTO;

import com.manxi.result.PageResult;
import com.manxi.result.Result;
import com.manxi.service.TrendsService;
import com.manxi.vo.TrendsVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/admin/trends")
@Api(tags = "管理端商家动态相关接口")
@Slf4j
public class TrendsController {
    @Autowired
    private TrendsService trendsService;

    /**
     * 新增动态
     *
     * @param trendsDTO
     * @return
     */
    @PostMapping
    @ApiOperation("新增动态")
    public Result save(@RequestBody TrendsDTO trendsDTO) {
        log.info("新增动态：{}", trendsDTO);
        trendsService.save(trendsDTO);
        return Result.success();
    }

    /**
     * 动态分页查询
     *
     * @param trendsPageQueryDTO
     * @return
     */
    @GetMapping("/page")
    @ApiOperation("动态分页查询")
    public Result<PageResult> page(TrendsPageQueryDTO trendsPageQueryDTO) {
        log.info("动态分页查询:{}", trendsPageQueryDTO);
        PageResult pageResult = trendsService.pageQuery(trendsPageQueryDTO);
        return Result.success(pageResult);
    }


    /**
     * 根据id查询动态
     *
     * @param id
     * @return
     */
    @GetMapping("{id}")
    @ApiOperation("根据id查询动态")
    public Result<TrendsVO> getById(@PathVariable Long id) {
        log.info("动态id:{}", id);
        TrendsVO trendsVO = trendsService.getById(id);
        return Result.success(trendsVO);
    }

    /**
     * 批量删除动态和删除单个动态
     *
     * @param ids
     * @return
     */
    @DeleteMapping
    @ApiOperation("批量删除动态和删除单个动态")
    public Result<String> delete(@RequestParam List<Long> ids) {
        log.info("动态id:{}", ids);
        trendsService.deleteBatch(ids);
        return Result.success();
    }

    /**
     * 更改动态信息
     *
     * @param trendsDTO
     * @return
     */
    @PutMapping
    @ApiOperation("更改动态信息")
    public Result<String> update(@RequestBody TrendsDTO trendsDTO) {
        log.info("更改动态信息:{}", trendsDTO);
        trendsService.update(trendsDTO);
        return Result.success();
    }

}
